package beans;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.ColumnTransformer;
import org.jasypt.util.password.ConfigurablePasswordEncryptor;

import form.userForm;

@Entity
@Table(name = "User_Right")
@NamedNativeQuery(name = "checkValidatedUser", query = "select * from UserRights where userRights_ID=?", resultClass = UserRights.class)
public class UserRights implements Serializable{

	private static final String ALGO_CHIFFREMENT = "SHA-256";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long userRights_ID;
	private String userMdp;
	
	//0 : incatif  1: lecture seulement    2 : lecture ecriture    3 : team leader
	private int userRightsIndex = 0;

	public UserRights() {
	}

	public UserRights(userForm form) {

		// constructeur where password is encrypted and saved
		ConfigurablePasswordEncryptor passwordEncryptor = new ConfigurablePasswordEncryptor();
		passwordEncryptor.setAlgorithm(ALGO_CHIFFREMENT);
		passwordEncryptor.setPlainDigest(false);
		this.userMdp = passwordEncryptor.encryptPassword(form.getUserMdp());
	}

	// ---------------------------- GETTERS AND SETTERS
	// ----------------------------------------------------------------------//
	// ------------------------------------------------------------------------------------------------------------------------//

	public long getUserRights_ID() {
		return userRights_ID;
	}

	public void setUserRights_ID(long userRights_ID) {
		this.userRights_ID = userRights_ID;
	}

	public String getUserMdp() {
		return userMdp;
	}

	public void setUserMdp(String userMdp) {
		this.userMdp = userMdp;
	}

	public int getUserRightsIndex() {
		return userRightsIndex;
	}

	public void setUserRightsIndex(int userRightsIndex) {
		this.userRightsIndex = userRightsIndex;
	}

}
